#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 13 21:57:25 2023

@author: liqingsimac
"""
import numpy as np
import matplotlib.pyplot as plt

A=plt.imread('rice3.png')

B=A[:,:,0]
#C=A[:,:,1]
#D=A[:,:,2]

U,S,Vh = np.linalg.svd(B)
m=400;n=600;p=10

S11=np.diag(S[0:p])
U1=U[:,0:p]
Vh1=Vh[0:p,:]

#B1=np.matmul(np.matmul(U1,S11),Vh1)
B1=U1@S11@Vh1
#plt.imshow(B,cmap='summer')
#plt.imshow(B1,cmap='summer')

fig = plt.figure()
ax=fig.add_subplot(121)
ax.imshow(B,cmap='summer')
bx=fig.add_subplot(122)
bx.imshow(B1,cmap='summer')

print('左图存储空间：',np.size(B))
print('右图存储空间：',np.size(U1)+np.size(S11)+np.size(Vh1))

